Skip to content

fix(security): sanitize gstack-slug output against shell injection#138

Open
elliotllliu wants to merge 1 commit intogarrytan:mainfrom
elliotllliu:fix/sanitize-gstack-slug
Open

fix(security): sanitize gstack-slug output against shell injection#138
elliotllliu wants to merge 1 commit intogarrytan:mainfrom
elliotllliu:fix/sanitize-gstack-slug

Conversation

@elliotllliu
Copy link

Summary

Fixes #133 — hardens bin/gstack-slug against shell injection when consumed via eval $(gstack-slug).

Problem

gstack-slug derives SLUG and BRANCH from git remote get-url origin and git rev-parse --abbrev-ref HEAD. The existing pipeline (sed + tr '/' '-') does not strip shell metacharacters like ;, $(), backticks, or |. Since the output is consumed via eval in 14+ skill templates, a malicious remote URL or branch name could execute arbitrary commands.

Fix

Added a sanitize() function that strips everything except [a-zA-Z0-9._-] via tr -cd. Applied to both SLUG and BRANCH before output. All existing eval $(gstack-slug) callers are automatically protected without template changes.

Risk context

Low severity — GitHub and GitLab enforce alphanumeric naming for orgs/repos/branches, so hosted repos are safe. This is defense-in-depth for self-hosted git servers or exotic remote URLs.

The eval $(gstack-slug) pattern used across 14+ skill templates
passes git-derived values (remote URL, branch name) through eval
without stripping shell metacharacters like ;, $(), backticks, |.

Add a sanitize function that strips everything except [a-zA-Z0-9._-]
from both SLUG and BRANCH before output. This hardens all existing
callers without requiring changes to any template file.

Risk was low (GitHub/GitLab enforce safe naming) but defense-in-depth
matters for self-hosted git servers or exotic remote URLs.

Fixes garrytan#133
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security] Low severity: shell injection hardening for eval $(gstack-slug) in /design-consultation

1 participant